package com.risetechnology.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.risetechnology.customviews.CustomFontTextView;
import com.risetechnology.data.Glossary;
import com.risetechnology.krystalkitchen1.R;

public class GlossaryListAdapter extends ArrayAdapter<Glossary> {

	private Context context;
	private int layoutId;
	private List<Glossary> data = null;

	public GlossaryListAdapter(Context context, int layoutId, List<Glossary> data) {
		super(context, layoutId, data);
		this.context = context;
		this.layoutId = layoutId;
		this.data = data;
	}

	public View getView(final int position, View convertView,
			ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(layoutId, parent, false);

			holder = new ViewHolder();

			holder.textViewTitle = (CustomFontTextView) convertView.findViewById(R.id.tv_title);
			holder.textViewContent = (CustomFontTextView) convertView.findViewById(R.id.tv_content);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.textViewTitle.setText(data.get(position).getTitle());
		holder.textViewContent.setText(data.get(position).getContent());
		
		convertView.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
			}
		});

		return convertView;
	}

	static class ViewHolder {
		CustomFontTextView textViewTitle;
		CustomFontTextView textViewContent;
	}
}
